#语法糖：python中交换两个元组可以直接用nums[l], nums[r] = nums[r], nums[l]。避免了tmp中间变量的使用

#leetcode题目283：移动零
#难度：简单
#时间复杂度：O(n)
#空间复杂度：O(1)
#方法：双指针
#要求原地修改

from typing import List
class Solution:
    def moveZeroes(self, nums: List[int]) -> None:
        n = len(nums)
        left = right = 0
        while right < n:
            if nums[right] != 0:
                nums[left], nums[right] = nums[right], nums[left]
                left += 1
            right += 1



#输入格式：0,1,0,3,12
nums = [0,1,0,3,12]
#预期输出：[1,3,12,0,0]

solution = Solution()
solution.moveZeroes(nums)
print(nums)

nums = [0]
#预期输出：[0]
solution.moveZeroes(nums)
print(nums)

